package com.fqgj.xjd.user.service.impl;

import com.fqgj.common.api.Response;
import com.fqgj.exception.common.ApiErrorException;
import com.fqgj.xjd.user.client.UserAuthMessageService;
import com.fqgj.xjd.user.client.request.UserAuthMessage;
import com.fqgj.xjd.user.dao.UserAuthMessageDao;
import com.fqgj.xjd.user.entity.UserAuthMessageEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ·
 *
 * @author liuming
 * Created on 上午10:19 2019/3/19.
 */
@Service("userAuthMessageService")
public class UserAuthMessageServiceImpl implements UserAuthMessageService {

    @Autowired
    UserAuthMessageDao userAuthMessageDao;

    @Override
    public Response addUserAuthMessage(UserAuthMessage userAuthMessage) {
        if (StringUtils.isBlank(userAuthMessage.getUserCode())) {
            throw new ApiErrorException("userCode is empty");
        }

        if (StringUtils.isBlank(userAuthMessage.getMessageJson())) {
            throw new ApiErrorException("messageJson is empty");
        }

        UserAuthMessageEntity userAuthMessageEntity = new UserAuthMessageEntity();
        userAuthMessageEntity.setUserCode(userAuthMessage.getUserCode());
        userAuthMessageEntity.setMessageJson(userAuthMessage.getMessageJson());
        userAuthMessageDao.insert(userAuthMessageEntity);

        return Response.ok();
    }
}
